package com.liqw.fastswing.ui.view;

import com.liqw.fastswing.domain.entity.User;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * We make this view abstract so that we can implement actions without having to know anything going on under
 * the hood. Anything to do with manipulating the actual View is done here, while manipulating the Model is done
 * in the Controller, which makes a concrete implementation of this view.
 *
 * Most of the code here gets generated by IntelliJ IDEA's GUI Designer.
 */
public abstract class MainView {
    private JPanel mainPanel;
    private JList<User> userList;
    private JButton newButton;
    private JButton viewButton;

    protected abstract void newButtonClicked();

    protected abstract void viewButtonClicked();

    public User getSelected() {
        return userList.getSelectedValue();
    }

    public void setUserListInfo(List<User> list) {
        userList = new JList<>();
        for (User user : list) {
            userList.add(new Label(user.getName()));
        }
    }

    protected MainView() {
        //"event" is definitely not used anywhere, in case you were trying to figure that out.
        newButton.addActionListener(event -> newButtonClicked());
        viewButton.addActionListener(event -> viewButtonClicked());
    }

    /**
     * @noinspection ALL
     */
    public JComponent getRootComponent() {
        return mainPanel;
    }
}
